package multithreadedgui.model;

import javax.swing.*;
import java.util.concurrent.ExecutionException;

/**
 * Use at own risk.
 * Creation data:
 * User: Alex
 * Date: 12/04/12
 * Time: 20:09
 */
public class PiTask extends SwingWorker<Double, Void> {
    private Callback<Double> callback;

    public PiTask(Callback<Double> callback) {
        this.callback = callback;
    }

    @Override
    protected Double doInBackground() throws Exception {
        return PiComputer.calculatePi();
    }

    @Override
    protected void done() {
        super.done();
        try {
            callback.call(get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
